# Version 0.1

# 基础镜像
FROM centos:7.4.1708

# 指定运行容器时的用户名或 UID，后续的 RUN、CMD、ENTRYPOINT 也会使用指定用户，镜像构建完成后，通过docker run运行容器时，可以通过-u参数来覆盖所指定的用户
# USER root

# 工作目录，类似于cd命令 设置工作目录后，Dockerfile中其后的命令RUN、CMD、ENTRYPOINT、ADD、COPY等命令都会在该目录下执行，docker run运行容器时，可以通过-w参数覆盖构建时所设置的工作目录
WORKDIR /root/

# 禁用yum的定位fastestmirror的功能
# 安装vim，中文支持以及一些常用软件
COPY docker/CentOS-Base.repo docker/yum.conf docker/epel.repo /tmp/

RUN \
echo 'export LANG=zh_CN.UTF-8' >> /etc/bashrc && \
echo 'export LC_ALL=zh_CN.UTF-8' >> /etc/bashrc && \
sed -i "s|.*enabled=1.*|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf && \
cp -rf /tmp/CentOS-Base.repo /etc/yum.repos.d/ && \
yum install -y epel-release && \
rm -rf /etc/yum.repos.d/* && \
rm -rf /etc/yum.conf && mv /tmp/yum.conf /etc/yum.conf && \
mv /tmp/CentOS-Base.repo /etc/yum.repos.d/ && \
mv /tmp/epel.repo /etc/yum.repos.d/ && \
yum install -y wget vim file psmisc net-tools htop kde-l10n-Chinese telnet less unzip && \
yum update -y glibc && \
yum install -y nginx && \
yum install -y php php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo php-pgsql php-pecl-redis php-soap && \
yum clean all && \
# 中文支持
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 && \
# 时区调整
rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
sed -i "s/user = apache/user = nginx/" /etc/php-fpm.d/www.conf && \
sed -i "s/group = apache/group = nginx/" /etc/php-fpm.d/www.conf && \
sed -i "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm\/php-fpm.sock/" /etc/php-fpm.d/www.conf && \
sed -i "s/;listen.owner = nobody/listen.owner = nginx/" /etc/php-fpm.d/www.conf && \
sed -i "s/;listen.group = nobody/listen.group = nginx/" /etc/php-fpm.d/www.conf && \
sed -i "s/;listen.mode = 0666/listen.mode = 0660/" /etc/php-fpm.d/www.conf && \
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php.ini && \
chmod -R 777 /var/lib/php/session

ADD config /var/www/html/yiwise-sms-control-panel/config/
ADD web /var/www/html/yiwise-sms-control-panel/web/
ADD docker/sms.conf /etc/nginx/conf.d/
RUN chmod -R 777 /var/www/html/

ENV LC_ALL "zh_CN.UTF-8"
CMD ["sh", "-c", "nginx && /usr/sbin/php-fpm --nodaemonize"]
